package com.stn.zjx.givingtreasure.activity.set;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.adapter.LanguageItemListAdapter;
import com.stn.zjx.givingtreasure.base.BaseActivity;
import com.stn.zjx.givingtreasure.constants.StnConstants;
import com.stn.zjx.givingtreasure.event.ExitEvent;
import com.stn.zjx.givingtreasure.event.NetWorkEvent;
import com.vondear.rxtools.RxSPTool;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LanguageSetActivity extends BaseActivity {


    @BindView(R.id.back_bt)
    RelativeLayout backBt;
    @BindView(R.id.action_title)
    TextView actionTitle;
    @BindView(R.id.web_title)
    TextView webTitle;
    @BindView(R.id.action_add_bt)
    RelativeLayout actionAddBt;
    @BindView(R.id.action_refresh)
    RelativeLayout actionRefresh;
    @BindView(R.id.exit)
    RelativeLayout exit;
    @BindView(R.id.sure_bt)
    TextView sureBt;
    @BindView(R.id.rv)
    RecyclerView rv;
    public LanguageItemListAdapter adapter;
    public LinearLayoutManager lm;
    @BindArray(value = R.array.language)
    public String[] language_list;




    @Subscribe(threadMode = ThreadMode.MAIN)
    public void ExitEvent(ExitEvent exitEvent){
        switch (exitEvent.flag){
            case ExitEvent.SWITCH_LANGUAGE_EXIT:
                finish();
                break;
        }
    }
    @Override
    public void networkStatus(NetWorkEvent netWorkEvent) {

    }

    @Override
    public void initComponent() {
        actionTitle.setText(getString(R.string.switch_language));
        lm=new LinearLayoutManager(this, OrientationHelper.VERTICAL,false);
        rv.setLayoutManager(lm);
        rv.setAdapter(adapter=new LanguageItemListAdapter(this));
        List<String> ar=new ArrayList<>();
         for (int i=0;i<language_list.length;i++){

             ar.add(language_list[i]);
         }

         if(RxSPTool.getInt(this, StnConstants.SWITCH_LANGUAGE_FLAG)==-1){
             adapter.position=0;
         }else{
             adapter.position=RxSPTool.getInt(this, StnConstants.SWITCH_LANGUAGE_FLAG);
         }

        adapter.refreshList(ar);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_language);
        ButterKnife.bind(this);
        initComponent();

    }


    @OnClick({R.id.back_bt})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_bt:
                finish();
                break;

        }
    }
}
